package com.hongning.railway.ui.main.fragments.college.itemviewModel;

import android.content.Context;
import android.databinding.ObservableField;
import android.databinding.ObservableInt;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;

import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.entity.resbean.ResVideoBean;
import com.hongning.railway.ui.main.fragments.college.LearnUnCompleteFragmentViewModel;
import com.hongning.railway.ui.main.fragments.college.VideoPlayActivity;
import com.hongning.railway.util.TimeUtils;

import cn.jzvd.JzvdStd;
import me.goldze.mvvmhabit.base.AppManager;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class VideoItemViewModel extends MultiItemViewModel {
    public ObservableField<String> videourl = new ObservableField<>();
    public ObservableField<String> img = new ObservableField<>();
    public ObservableField<String> time = new ObservableField<>();
    public ObservableField<ResVideoBean> videoData = new ObservableField<>();
    public Drawable drawableImg;
    public ObservableField<String> statu = new ObservableField<>();
    public ObservableInt statucolor = new ObservableInt();
    public BindingCommand videoClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putString(Constant.EXTRA_DATA,videoData.get().getNewsContent());
            bundle.putString(Constant.EXTRA_ID,videoData.get().getNewsId());
            viewModel.startActivity(VideoPlayActivity.class,bundle);
           // JCVideoPlayerStandard.startFullscreen(this, JZVideoPlayerStandard.class, "http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4", "嫂子辛苦了");
        }
    });
    public VideoItemViewModel(@NonNull BaseViewModel viewModel, ResVideoBean resVideoBean,Boolean isComplete) {
        super(viewModel);
        drawableImg = ContextCompat.getDrawable(viewModel.getApplication(), R.mipmap.icon_app_default);
        videourl.set(resVideoBean.getNewsContent());
        img.set(resVideoBean.getAppCoverImg());
        time.set(TimeUtils.getFormatTimeHHMM(resVideoBean.getShowTime()*1000));
        multiItemType(resVideoBean.getType());
        videoData.set(resVideoBean);
        if (isComplete){
            statu.set("已完成");
            statucolor.set(viewModel.getApplication().getResources().getColor(R.color.color_9D9D9D));
        }else {
            statu.set("未完成");
            statucolor.set(viewModel.getApplication().getResources().getColor(R.color.colorPrimary));
        }

    }


}
